package com.lzx.guanchajava.util;

import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.os.Bundle;

import com.lzx.guanchajava.view.activity.MainActivity;
import com.tencent.bugly.Bugly;

import org.litepal.LitePal;

public class App extends Application {

    private static Context mContext;



    public static Context getContext() {
        return mContext;
    }


    @Override
    public void onCreate() {
        super.onCreate();
        mContext = getApplicationContext();

        //Bmob.initialize(this, "e8900e00fcffac34af0607560e47407a")
        LitePal.initialize(this);
        Bugly.init(getApplicationContext(), "6b5ef0fe3b", false);


    }

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        registerActivityLifecycleCallbacks(callbacks);
    }

    ActivityLifecycleCallbacks callbacks = new ActivityLifecycleCallbacks() {
        @Override
        public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
            if (activity instanceof MainActivity) {
                ActivityStatic.getInstance().setActivity(activity);
            }
        }

        @Override
        public void onActivityStarted(Activity activity) {

        }

        @Override
        public void onActivityResumed(Activity activity) {

        }

        @Override
        public void onActivityPaused(Activity activity) {

        }

        @Override
        public void onActivityStopped(Activity activity) {
        }

        @Override
        public void onActivitySaveInstanceState(Activity activity, Bundle outState) {

        }

        @Override
        public void onActivityDestroyed(Activity activity) {
            /*if (activity == ContextBean.getInstance().getActivity()) {
                ContextBean.getInstance().setActivity(null);
            }*/
            if (activity instanceof MainActivity) {
                ActivityStatic.getInstance().destroyActivity();
            }
        }
    };
}
